package com.ruoyi.common.mq.rabbit.service;

import com.ruoyi.common.mq.core.Sender;
import com.ruoyi.common.mq.rabbit.config.RabbitMQConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SenderImpl implements Sender {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public void send(String queueName, Object message) {
        // 修改为使用交换机和路由键
        rabbitTemplate.convertAndSend(
                RabbitMQConfig.LOG_EXCHANGE,  // 使用配置的交换机
                RabbitMQConfig.LOG_ROUTING_KEY,  // 使用配置的路由键
                message,
                m -> {
                    // 设置消息属性
                    m.getMessageProperties().setContentType("application/json");
                    m.getMessageProperties().setContentEncoding("UTF-8");
                    return m;
                }
        );
    }
}